package com.example.backend.service.impl;

import com.example.backend.mapper.DataMapper;
import com.example.backend.mapper.FoodMapper;
import com.example.backend.pojo.Data;
import com.example.backend.pojo.Food;
import com.example.backend.pojo.Restaurant;
import com.example.backend.service.DataService;
import com.example.backend.service.RestaurantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class DataSerivceImpl implements DataService {
    @Autowired
    private DataMapper dataMapper;
    @Autowired
    private FoodMapper foodMapper;

    @Autowired
    private RestaurantService restaurantService;

    @Override
    public List<Data> daydata(Integer restaurantid) {
        return dataMapper.daydata(restaurantid);
    }

    @Override
    public List<Data> monthdata(Integer restaurantid) {
        return dataMapper.monthdata(restaurantid);

    }

    @Override
    public List<Food> dayfood(Integer restaurantid) {
        //food 先出去来，再放入
        List<Food> foods = foodMapper.getall(restaurantid);
        for (Food f:foods){
            f.setDate(dataMapper.dayfood(Integer.valueOf(f.getFoodid())));
        }
        return foods;

    }

    @Override
    public List<Food> monthfood(Integer restaurantid) {
        List<Food> foods = foodMapper.getall(restaurantid);
        for (Food f:foods){
            f.setDate(dataMapper.monthfood(Integer.valueOf(f.getFoodid())));
        }
        return foods;
    }

    @Override
    public List<Restaurant> dayres() {
        List<Restaurant> res = restaurantService.getall();
        for (Restaurant r:res){
            r.setDate(dataMapper.daydata(Integer.valueOf(r.getRestaurantid())));
        }
        return res;
    }

    @Override
    public List<Restaurant> monthres() {
        List<Restaurant> res = restaurantService.getall();
        for (Restaurant r:res){
            r.setDate(dataMapper.monthdata(Integer.valueOf(r.getRestaurantid())));
        }
        return res;
    }

    @Override
    public List<Data> allday() {
        return  dataMapper.allday();
    }

    @Override
    public List<Data> allmonth() {
        return dataMapper.allmonth();
    }

    @Override
    public Data allall() {
        return dataMapper.allall();
    }

    @Override
    public List<Data> allres() {
        return dataMapper.allres();
    }
    @Override
    public Data useralldate(Integer userid) {
        return dataMapper.useralldate(userid);
    }
    @Override
    public List<Data> usermonthdate(Integer userid) {
        return dataMapper.usermonthdate(userid);
    }

}
